﻿@{
    ViewBag.Title = "ManageService";
    Layout = "~/Views/Shared/_Layout2.cshtml";
    var user = ViewData["user"] as SmallJob.Model.User;
}
<div class="service-detail">
    <div class="service-detail-container">
        <div class="row-fluid">
            <div class="span12 service-detail-box main-column">
                <div class="span12inner">
                    <h1>Quản lý dịch vụ</h1>
                    <table class="table table-bordered">
                        <tbody>
                            <tr>
                                <td>
                                    <h1 class="text-center">@ViewData["statisticwaitaccept"]</h1>
                                    <h4 class="text-center">Chờ Đồng ý</h4>
                                </td>
                                 <td>
                                    <h1 class="text-center">@ViewData["statisticwaitdone"]</h1>
                                    <h4 class="text-center">Chờ kết thúc</h4>
                                </td>
                                <td>                                             
                                    <h1 class="text-center">@ViewData["statisticprocess"]</h1>
                                    <h4 class="text-center">Chờ bàn giao</h4>
                                </td>
                                <td>
                                    <h1 class="text-center">@ViewData["statisticdone"]</h1>
                                    <h4 class="text-center">Đã hoàn thành</h4>
                                </td>
                                <td>
                                    <h1 class="text-center">@ViewData["statisticcancel"]</h1>
                                    <h4 class="text-center">Bị hủy</h4>
                                </td>
                                <td>
                                    <h1 class="text-center">@SmallJob.Services.Code.UserUtility.FormatCurrency(Convert.ToDouble(ViewData["totalmoney"]))</h1>
                                    <h4 class="text-center">Đã thu về</h4>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <ul class="nav nav-tabs" id="myTab">
                        <li class="active">
                            <a href="#waitdone">Chờ bàn giao</a>
                        </li>
                        <li><a href="#done">Đã hoàn thành</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="waitdone">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Tên dịch vụ</th>
                                        <th>Giá trị</th>
                                        <th>Thời hạn</th>
                                        <th>Tình trạng</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in ViewData["waitdone"] as List<SmallJob.Model.Order>)
                                    {
                                        var remain = (DateTime)(item.Deadline ?? DateTime.Now) - DateTime.Now;
                                        var isover = (remain.TotalMinutes < 0);
                                        if (isover) { remain = remain.Negate(); }
                                        var client = (item.SellerID == user.ID ? item.Buyer : item.Seller);
                                        <tr>
                                            <td>
                                                <a href="/@(string.IsNullOrWhiteSpace(client.UserName) ? client.ID.ToString() : client.UserName)">
                                                    <img style="width:40px;height:40px;" rel="tooltip" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="@client.ProperName" src="@(string.IsNullOrWhiteSpace(client.Avatar) ? Url.Content("~/Content/img/blank-avatar.jpg") : client.Avatar + "?w=40&amp;h=40&amp;q=90&amp;format=jpg&amp;mode=crop")">
                                                </a>
                                            </td>
                                            <td><a href="@Url.Action("Details", "Order", new { id = item.ID })">@(item.Provide == null ? item.Request.Title : item.Provide.Title)</a></td>
                                            <td>@SmallJob.Services.Code.UserUtility.FormatCurrency(Convert.ToDouble(item.Price))</td>
                                            <td><span class="label @(isover ? "label-important" : "label-info")">@remain.Days ngày @remain.Hours giờ @remain.Minutes phút</span></td>
                                            <td>
                                                @if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.WaitProgress)
                                                {
                                                    <button class="btn btn-small btn-info disabled" type="button">Chờ Xác Nhận</button>
                                                }
                                                else if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.InProgress)
                                                {
                                                    <button class="btn btn-small btn-primary disabled" type="button">Đang làm</button>
                                                }
                                                else if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.Rejected)
                                                {
                                                    <button class="btn btn-small btn-warning disabled" type="button">Cần làm lại</button>
                                                }
                                                else if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.WaitDone)
                                                {
                                                    <button class="btn btn-small btn-success disabled" type="button">Chờ kết quả</button>
                                                }
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="tab-pane" id="done">

                            <table class="table">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Tên dịch vụ</th>
                                        <th>Giá trị</th>
                                        <th>Ngày Kết thúc</th>
                                        <th>Tình trạng</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in ViewData["done"] as List<SmallJob.Model.Order>)
                                    {
                                        var client = (item.SellerID == user.ID ? item.Buyer : item.Seller);
                                        <tr>
                                            <td>
                                                <a href="/@(string.IsNullOrWhiteSpace(client.UserName) ? client.ID.ToString() : client.UserName)">
                                                    <img style="width:40px;height:40px;" rel="tooltip" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="@client.ProperName" src="@(string.IsNullOrWhiteSpace(client.Avatar) ? Url.Content("~/Content/img/blank-avatar.jpg") : client.Avatar + "?w=40&amp;h=40&amp;q=90&amp;format=jpg&amp;mode=crop")">
                                                </a>
                                            </td>
                                            <td><a href="@Url.Action("Details", "Order", new { id = item.ID })">@(item.Provide == null ? item.Request.Title : item.Provide.Title)</a></td>
                                            <td>@SmallJob.Services.Code.UserUtility.FormatCurrency(Convert.ToDouble(item.Price))</td>
                                            <td><span class="label label-info">@item.ModifiedDate.ToString("dd/MM/yyyy hh:mm tt")</span></td>
                                            <td>
                                                @if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.Done)
                                                {
                                                    <button class="btn btn-small btn-success disabled" type="button">Đơn hàng thành công</button>
                                                }
                                                else if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.Failed)
                                                {
                                                    <button class="btn btn-small btn-danger disabled" type="button">Đơn hàng thất bại</button>
                                                }
                                                else if (item.Status == (int)SmallShop.Services.Code.OrderStatusV2.Cancel)
                                                {
                                                    <button class="btn btn-small btn-inverse disabled" type="button">Đơn hàng bị hủy</button>
                                                }
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#myTab a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    })
</script>
